package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysBrand;
import com.ruoyi.system.service.ISysBrandService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品品牌Controller
 * 
 * @author ruoyi
 * @date 2020-12-13
 */
@Controller
@RequestMapping("/system/brand")
public class SysBrandController extends BaseController
{
    private String prefix = "system/brand";

    @Autowired
    private ISysBrandService sysBrandService;

    @RequiresPermissions("system:brand:view")
    @GetMapping()
    public String brand()
    {
        return prefix + "/brand";
    }

    /**
     * 查询商品品牌列表
     */
    @RequiresPermissions("system:brand:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysBrand sysBrand)
    {
        startPage();
        List<SysBrand> list = sysBrandService.selectSysBrandList(sysBrand);
        return getDataTable(list);
    }

    /**
     * 导出商品品牌列表
     */
    @RequiresPermissions("system:brand:export")
    @Log(title = "商品品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysBrand sysBrand)
    {
        List<SysBrand> list = sysBrandService.selectSysBrandList(sysBrand);
        ExcelUtil<SysBrand> util = new ExcelUtil<SysBrand>(SysBrand.class);
        return util.exportExcel(list, "brand");
    }

    /**
     * 新增商品品牌
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存商品品牌
     */
    @RequiresPermissions("system:brand:add")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysBrand sysBrand)
    {
        return toAjax(sysBrandService.insertSysBrand(sysBrand));
    }

    /**
     * 修改商品品牌
     */
    @GetMapping("/edit/{brandId}")
    public String edit(@PathVariable("brandId") Long brandId, ModelMap mmap)
    {
        SysBrand sysBrand = sysBrandService.selectSysBrandById(brandId);
        mmap.put("sysBrand", sysBrand);
        return prefix + "/edit";
    }

    /**
     * 修改保存商品品牌
     */
    @RequiresPermissions("system:brand:edit")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysBrand sysBrand)
    {
        return toAjax(sysBrandService.updateSysBrand(sysBrand));
    }

    /**
     * 删除商品品牌
     */
    @RequiresPermissions("system:brand:remove")
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysBrandService.deleteSysBrandByIds(ids));
    }
}
